<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
use app\api\middleware\BlockerMiddleware;
use think\facade\Route;
use think\facade\Config;
use think\Response;
use app\http\middleware\AllowOriginMiddleware;
Route::group(function () {
    /*
     * 测试
     * *********************/
    Route::any('wxpay/test', 'v3.WxPayController/tt')->option(['real_name' => '微信支付测试']);//微信wxpay类测试
    Route::any('profitSharing', 'v3.ProfiTharingController/profitSharing')->option(['real_name' => '请求单次分账接口']);//请求单次分账接口
    Route::any('addReceiverv2', 'v3.ProfiTharingController/addReceiver')->option(['real_name' => '添加分账接收方']);//添加分账接收方

    //微信支付
//    Route::any('pay/notify/:type', 'v3.PayController/notify')->option(['real_name' => '支付回调']);//支付回调 原版回调
    Route::any('notify/placeOrder/:type', 'v3.NotifyController/notify')->option(['real_name' => '易宝支付回调']);//易宝支付回调 新版
    Route::any('notify/wx_notify', 'v3.NotifyController/wx_notify')->option(['real_name' => '支付回调服务商版']);//支付回调 服务商版
    Route::any('notify/refund_notify', 'v3.NotifyController/refund_notify')->option(['real_name' => '微信退款回调服务商版']);//微信退款回调服务商版
    Route::any('wx_tui', 'v3.SampleController/wx_tui')->option(['real_name' => '微信退款接口版，直退']);//微信退款接口版，直退
    Route::any('wx_tui2', 'v3.SampleController/wx_tui2')->option(['real_name' => '微信退款接口版，直退商户版本']);//微信退款接口版2，直退
    Route::any('get_order', 'v3.SampleController/get_order')->option(['real_name' => '微信支付订单号查询订单']);//微信支付订单号查询订单
    Route::any('get_order2', 'v3.SampleController/get_order2')->option(['real_name' => '微信支付订单号查询订单2']);//微信支付订单号查询订单直营商户


    //微信分账
    Route::any('addReceivers', 'v3.SampleController/addReceivers')->option(['real_name' => '添加分账接收方']);//添加分账接收方
    Route::any('delReceivers', 'v3.SampleController/delReceivers')->option(['real_name' => '删除分账接收方']);//删除分账接收方
    Route::any('divide', 'v3.SampleController/divide')->option(['real_name' => '单次分账']);//单次分账
    Route::any('get_amounts', 'v3.SampleController/get_daifen_amounts')->option(['real_name' => '查询剩余待分金额']);//查询剩余待分金额
    Route::any('get_split_result', 'v3.SampleController/get_split_result')->option(['real_name' => '查询分账结果API']);//查询分账结果API
    Route::any('return_divide', 'v3.SampleController/return_divide')->option(['real_name' => '分账回退']);//分账回退
    Route::any('unfreeze', 'v3.SampleController/unfreeze')->option(['real_name' => '解冻剩余资金']);//解冻剩余资金
    Route::any('get_daifen_amounts', 'v3.SampleController/get_daifen_amounts')->option(['real_name' => '查询剩余待分金额']);//查询剩余待分金额
    Route::any('combine', 'v3.SampleController/combine')->option(['real_name' => '合单支付']);//合单支付


    //微信特约商户进件接口
    Route::any('mediaUpload', 'v3.Wxpaymch/mediaUpload')->option(['real_name' => '微信特约商户上传图片']);//微信特约商户上传图片
    Route::any('applyment', 'v3.Wxpaymch/subApplyment')->option(['real_name' => '微信特约商户进件接口']);//微信特约商户进件接口
    Route::any('yy_applyment', 'v3.Wxpaymch/yy_applyment')->option(['real_name' => '商户开户意愿确认提交']);//商户开户意愿确认提交
    Route::get('slect_bc_applyment', 'v3.Wxpaymch/slect_bc_applyment')->option(['real_name' => '查询微信特约商户审核状态']);//查询微信特约商户审核状态


})->option(['mark' => 'serve', 'mark_name' => '服务接口']);




Route::group(function () {

    /** 微信*/
    Route::group(function (){
        Route::get('wx/subApplyment', 'v3.WxController/subApplyment')->name('subApplyment');   //特约商户进件（提交申请单）
        Route::get('wx/get_openid', 'v3.WxController/get_openid')->name('get_openid');   //查看用户openid
        Route::get('wxpay/unifyPay', 'v3.WxPayController/unifyPay')->name('unifyPay');   //特约商户创建订单
    });

    /** 测试*/
    Route::group(function (){
        Route::get('wx/t', 'v3.TController/wxpay')->name('test');
        Route::get('wx/t2', 'v3.TController/aa')->name('aa');

    });


    /** 支付宝 */
    Route::group(function (){
        // 获取支付宝access_token
        Route::get('getAlipayAccessToken', 'v3.alipay.AlipayController/getAccessToken')->name('getAlipayAccessToken')->middleware(\app\http\middleware\AllowOriginMiddleware::class);
        // 获取支付宝配置信息
        Route::post('Ali/getSysConfig', 'v3.alipay.AlipayController/getSysConfig')->name('getSysConfig')->middleware(\app\http\middleware\AllowOriginMiddleware::class);
        // 申请免押
        Route::post('alipayOrderSave', 'v3.alipay.AlipayController/alipayOrderSave')->name('alipayOrderSave'); // 支付宝免押订单提交
        Route::get('applyFreezeOrder', 'v3.alipay.AlipayController/applyFreezeOrder')->name('applyFreezeOrder'); // 申请免押
        Route::get('alipayOrderList', 'v3.alipay.AlipayController/alipayOrderList')->name('alipayOrderList'); // 支付宝下单列表页
        // 获取用户芝麻分
        Route::get('getZhimaCreditScoreGetRequest', 'v3.alipay.AlipayController/getZhimaCreditScoreGetRequest')->name('getZhimaCreditScoreGetRequest');//首页
        // 冻结资金
        Route::post('AlipayFundAuthOrderAppFreezeRequest', 'v3.alipay.AlipayController/AlipayFundAuthOrderAppFreezeRequest')->name('AlipayFundAuthOrderAppFreezeRequest');//冻结资金
    });


})->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\api\middleware\StationOpenMiddleware::class)->middleware(\app\api\middleware\AuthTokenMiddleware::class, false);




Route::miss(function () {
    if (app()->request->isOptions()) {
        $header = Config::get('cookie.header');
        unset($header['Access-Control-Allow-Credentials']);
        return Response::create('ok')->code(200)->header($header);
    } else
        return Response::create()->code(404);
});
